﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using ProjManagSolution.pmMyWebService;

namespace ProjManagSolution
{
    public partial class CreatePhase : ChildWindow
    {
        // List of auto collection
        protected List<milestone> ml = new List<milestone>(); //inputed milestone list
        protected List<Milestone> listMilestone = new List<Milestone>();

        public CreatePhase(List<milestone> in_ml)
        {
            InitializeComponent();

            //get the input milestone list
            ml = in_ml;

            // Add items into collection;
            AddCollectionMilestone();
            // Bind datacontext
            autoboxMilestone.DataContext = listMilestone;
        }

        protected bool Input_Validate()
        {
            if (txtboxPhaseName.Text == "")
            {
                MessageBox.Show("Phase name cannot be empty!");
                return false;
            }

            else if (autoboxMilestone.SelectedItem == null)
            {
                MessageBox.Show("A phase must belong to a milestone!");
                return false;
            }

            return true;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if(Input_Validate())
                this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        // Add items into collection;
        private void AddCollectionMilestone()
        {
            for (int i = 0; i < ml.Count; ++i)
            {
                listMilestone.Add(new Milestone() { 
                    Name = ml[i].milestone_name,
                    ID = ml[i].milestone_id.ToString()
                });
            }
        }
    }
}

